#include<iostream>
#include<vector>
using namespace std;

int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {

    int n = gas.size();
    vector<int>getGas(gas.size(), 0);
    for (int i = 0; i < gas.size(); i++)
    {
        getGas[i] = gas[i] - cost[i];
    }


    for (int i = 0; i < n; i++)
    {
        int curGas = 0;
        for (int j = 0; j < n; j++)
        {
            curGas += getGas[(i + j) % n];
            if (curGas < 0)
            {
                if (i + j < n)
                {
                    i = i + j;
                }
                else
                {
                    return -1;
                }
                break;
            }
            if (j == n - 1)
            {
                return i;
            }
        }
    }
    return -1;
}

int main()
{

    vector<int>gas = { 2,3,4 };
    vector<int>nus = { 3,4,3};
    canCompleteCircuit(gas, nus);
    return 0;
}